/*=========================================================================
Elite College as Engines of Upward Mobility: Evidence from Colombia's Ser Pilo Paga
Authors: Juliana Londoño-Vélez, Catherine Rodriguez, Fabio Sánchez
and Luis Esteban Álvarez-Arango

Creation date: June 6th, 2025
--------------------------------------------------------------------------
Figure A4
=========================================================================*/

use "${data}/heterogeneities_access_0_hq.dta", clear

replace nombre = "cc" if _n==1
replace nombre = "cr" if _n==2
replace nombre = "sec" if _n==3
replace nombre = "ser" if _n==4
replace nombre = "cs" if _n==5
replace nombre = "ci" if _n==6
replace nombre = "cc0" if _n==7
replace nombre = "cr0" if _n==8
replace nombre = "pc" if _n==9
replace nombre = "pr" if _n==10
replace nombre = "bwc" if _n==11
replace nombre = "bwr" if _n==12
replace nombre = "nec0" if _n==13
replace nombre = "nec" if _n==14
replace nombre = "ner0" if _n==15
replace nombre = "ner" if _n==16
replace nombre = "n" if _n==17

xpose, clear varname

rename v1 cc
rename v2 cr
rename v3 sec
rename v4 ser
rename v5 cs
rename v6 ci
rename v7 cc0
rename v8 cr0
rename v9 pc
rename v10 pr
rename v11 bwc
rename v12 bwr
rename v13 nec0
rename v14 nec
rename v15 ner0
rename v16 ner
rename v17 n
rename _varname nombre
drop if _n==1

order nombre
	
gen 	x = 1 if nombre=="total_saber11"
replace x = 2 if nombre=="stratum_1_saber11"
replace x = 3 if nombre=="stratum_2_saber11"
replace x = 4 if nombre=="stratum_3_saber11"

gen 	name = "Total"	if x==1
replace name = "1 (poorest)" if x==2
replace name = "2" if x==3
replace name = "3 (less poor)" if x==4

labmask x, values(name)

twoway 	(rcap cs ci x if !missing(x), lcolor(black)) ///
		(scatter cc x if !missing(x), mcolor(black) msymbol(O)) ///
		,ytitle(RD Coefficient and 95% CI)  ///
		legend(off) xsize(8) xtitle("Socioeconomic stratum") ///
		graphregion(color(white)) xsc(r(0.5 4.5)) xlab(1 2 3 4, valuelabel labsize(medlarge)) ///
		caption(Sample restricted to low-SES individuals.)
graph export "${outcomes}/FigA4.pdf", replace width(20)
